let express = require('express');
let router = express.Router();
let fs = require('fs')

function getPage(arr, page) {
  let pageStart = (page - 1) * 3
  return arr.splice(pageStart, 3)
}

router.get('/list', (req, res, next) => {
  let readDir = fs.readdirSync("./public/upload/").reverse();
  let page = req.query.page;
  if (!page || page <= 0)
    page = 1
  console.log('获取第%s页视频', page)
  let result = getPage(readDir, page)
  res.json({
    code: 1,
    data: result
  });
});

module.exports = router;
